home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / pandoras.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  5KB  |  178 lines

  1. #include "driver.h"
  2. #include "vidhrdw/generic.h"
  3.  
  4. static int flipscreen;
  5. static struct tilemap *layer0;
  6. extern unsigned char *pandoras_sharedram;
  7.  
  8. /***********************************************************************
  9.  
  10.   Convert the color PROMs into a more useable format.
  11.  
  12.   Pandora's Palace has one 32x8 palette PROM and two 256x4 lookup table
  13.   PROMs (one for characters, one for sprites).
  14.   The palette PROM is connected to the RGB output this way:
  15.  
  16.   bit 7 -- 220 ohm resistor  -- BLUE
  17.         -- 470 ohm resistor  -- BLUE
  18.         -- 220 ohm resistor  -- GREEN
  19.         -- 470 ohm resistor  -- GREEN
  20.         -- 1  kohm resistor  -- GREEN
  21.         -- 220 ohm resistor  -- RED
  22.         -- 470 ohm resistor  -- RED
  23.   bit 0 -- 1  kohm resistor  -- RED
  24.  
  25. ***************************************************************************/
  26. void pandoras_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  27. {
  28.     int i;
  29.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  30.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  31.  
  32.     for (i = 0; i < Machine->drv->total_colors; i++)
  33.     {
  34.         int bit0, bit1, bit2;
  35.  
  36.         /* red component */
  37.         bit0 = (*color_prom >> 0) & 0x01;
  38.         bit1 = (*color_prom >> 1) & 0x01;
  39.         bit2 = (*color_prom >> 2) & 0x01;
  40.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  41.  
  42.         /* green component */
  43.         bit0 = (*color_prom >> 3) & 0x01;
  44.         bit1 = (*color_prom >> 4) & 0x01;
  45.         bit2 = (*color_prom >> 5) & 0x01;
  46.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  47.  
  48.         /* blue component */
  49.         bit0 = 0;
  50.         bit1 = (*color_prom >> 6) & 0x01;
  51.         bit2 = (*color_prom >> 7) & 0x01;
  52.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  53.  
  54.         color_prom++;
  55.     }
  56.  
  57.     /* color_prom now points to the beginning of the lookup table */
  58.  
  59.     /* sprites */
  60.     for (i = 0;i < TOTAL_COLORS(1);i++)
  61.         COLOR(1,i) = *(color_prom++) & 0x0f;
  62.  
  63.     /* characters */
  64.     for (i = 0;i < TOTAL_COLORS(0);i++)
  65.         COLOR(0,i) = (*(color_prom++) & 0x0f) + 0x10;
  66. }
  67.  
  68. /***************************************************************************
  69.  
  70.   Callbacks for the TileMap code
  71.  
  72. ***************************************************************************/
  73.  
  74. static void get_tile_info0(int tile_index)
  75. {
  76.     unsigned char attr = colorram[tile_index];
  77.     SET_TILE_INFO(0,videoram[tile_index] + ((attr & 0x10) << 4),attr & 0x0f);
  78.     tile_info.flags = TILE_FLIPYX((attr & 0xc0) >> 6);
  79.     tile_info.priority = (attr & 0x20) >> 5;
  80. }
  81.  
  82. /***************************************************************************
  83.  
  84.     Start the video hardware emulation.
  85.  
  86. ***************************************************************************/
  87.  
  88. int pandoras_vh_start(void)
  89. {
  90.     layer0 = tilemap_create(get_tile_info0,tilemap_scan_rows,TILEMAP_OPAQUE,8,8,32,32);
  91.  
  92.     if (!layer0)
  93.         return 1;
  94.  
  95.     return 0;
  96. }
  97.  
  98. /***************************************************************************
  99.  
  100.   Memory Handlers
  101.  
  102. ***************************************************************************/
  103.  
  104. READ_HANDLER( pandoras_vram_r )
  105. {
  106.     return videoram[offset];
  107. }
  108.  
  109. READ_HANDLER( pandoras_cram_r )
  110. {
  111.     return colorram[offset];
  112. }
  113.  
  114. WRITE_HANDLER( pandoras_vram_w )
  115. {
  116.     if (videoram[offset] != data)
  117.     {
  118.         tilemap_mark_tile_dirty(layer0,offset);
  119.         videoram[offset] = data;
  120.     }
  121. }
  122.  
  123. WRITE_HANDLER( pandoras_cram_w )
  124. {
  125.     if (colorram[offset] != data)
  126.     {
  127.         tilemap_mark_tile_dirty(layer0,offset);
  128.         colorram[offset] = data;
  129.     }
  130. }
  131.  
  132. WRITE_HANDLER( pandoras_scrolly_w )
  133. {
  134.     tilemap_set_scrolly(layer0,0,data);
  135. }
  136.  
  137. WRITE_HANDLER( pandoras_flipscreen_w )
  138. {
  139.     flipscreen = data;
  140.     tilemap_set_flip(ALL_TILEMAPS, flipscreen ? (TILEMAP_FLIPY | TILEMAP_FLIPX) : 0);
  141. }
  142.  
  143. /***************************************************************************
  144.  
  145.   Screen Refresh
  146.  
  147. ***************************************************************************/
  148.  
  149. static void draw_sprites(struct osd_bitmap *bitmap, unsigned char* sr)
  150. {
  151.     int offs;
  152.  
  153.     for (offs = 0; offs < 0x100; offs += 4)
  154.     {
  155.         int sx = sr[offs + 1];
  156.         int sy = 240 - sr[offs];
  157.         int nflipx = sr[offs + 3] & 0x40;
  158.         int nflipy = sr[offs + 3] & 0x80;
  159.  
  160.         drawgfx(bitmap,Machine->gfx[1],
  161.             sr[offs + 2],
  162.             sr[offs + 3] & 0x0f,
  163.             !nflipx,!nflipy,
  164.             sx,sy,
  165.             &Machine->drv->visible_area,TRANSPARENCY_COLOR,0);
  166.     }
  167. }
  168.  
  169. void pandoras_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  170. {
  171.     tilemap_update( layer0 );
  172.     tilemap_render( layer0 );
  173.  
  174.     tilemap_draw( bitmap, layer0, 1 );
  175.     draw_sprites( bitmap, &pandoras_sharedram[0x800] );
  176.     tilemap_draw( bitmap, layer0, 0 );
  177. }
  178.